package main.edu.csu.shan.pojo;


import main.edu.csu.shan.util.HanUtils;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;

/**
 * 切分的字组合，并非真正意义上的词
 */
public class Term {
    public String value;   // 词的结构
    public int count;  // 词频

    public Term(String value, int count) {
        this.value = value;
        this.count = count;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }


    public static void main(String[] args) {
        Set<String> set = new HashSet<>();
        set.add("中国银行");
        set.add("重庆银行");
        set.add("上海");
        set.add("北京");
        set.add("中国移动");
        set.add("长沙");    set.add("阿里");set.add("百度");


        // set.stream().sorted(Comparator.);

   /*     set.stream().sorted((o1, o2) -> {
            HanyuPinyinOutputFormat pinyinOutputFormat = new HanyuPinyinOutputFormat();
            String  str1 ="" ;
            String  str2 ="";
            try {
                str1 = PinyinHelper.toHanyuPinyinString(o1, pinyinOutputFormat, " ");
                str2 = PinyinHelper.toHanyuPinyinString(o2, pinyinOutputFormat, " ");

            } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
                badHanyuPinyinOutputFormatCombination.printStackTrace();
            }
            System.out.println(str1 +"    " + str2);
            return str2.compareTo(str1);
        });*/

        set.stream().sorted((o1, o2) -> HanUtils.firstPinyinCharStr(o2).compareTo(HanUtils.firstPinyinCharStr(o1)));


        System.out.println(set.toString());
    }
}
